package com.woke.adapter;

import java.util.ArrayList;
import java.util.List;

import com.zhongcai.online.R;
import com.woke.data.Data_myloan;
import com.woke.method.Intentnet;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class Myloanadter extends BaseAdapter{
	private LayoutInflater mInflater;
	private List<Data_myloan> datalist;
	private String getuser_id;

	public Myloanadter(LayoutInflater minflater, ArrayList<Data_myloan> datalist, String getuser_id) {
		this.mInflater = minflater;
		this.datalist = datalist;
		this.getuser_id = getuser_id;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return datalist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	class Holder {
		TextView mText_money;
		TextView mText_for;
		TextView mText_order;
		TextView mText_time;
		TextView mText_date;
		ImageView mImage1;
		ImageView mImage2;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		if(convertView == null){
			holder = new Holder();
			convertView = mInflater.inflate(R.layout.item_adapter_myloan, null);
			holder.mText_money = (TextView) convertView.findViewById(R.id.item_myloan_money);
			holder.mText_for = (TextView) convertView.findViewById(R.id.item_myloan_for);
			holder.mText_order = (TextView) convertView.findViewById(R.id.item_myloan_order);
			holder.mText_time = (TextView) convertView.findViewById(R.id.item_myloan_time);
			holder.mText_date = (TextView) convertView.findViewById(R.id.item_myloan_date);
			holder.mImage1 = (ImageView) convertView.findViewById(R.id.item_myloan_image1);
			holder.mImage2 = (ImageView) convertView.findViewById(R.id.item_myloan_image2);
			convertView.setTag(holder);
		}else{
			 holder = (Holder) convertView.getTag();
		}
		Data_myloan data = datalist.get(position);
		holder.mText_money.setText(data.quota_money+"元");
//		if(data.quota_type.equals("0")){
			holder.mText_for.setText(data.quota_use);
//		}else if(data.quota_type.equals("1")){
//			holder.mText_for.setText("����");
//		}else{
//			holder.mText_for.setText("����");
//		} 
		holder.mText_order.setText(data.id);
//		if(position == 0){
//			Log.e(""+data.repay_date, ""+Intentnet.getStrTime(data.creat_date));
//		}
		holder.mText_date.setText(Intentnet.getStrTime(data.creat_date));
		holder.mText_time.setText(data.exp_date+"天");
		String user_id = data.user_id;
		if(user_id.equals(getuser_id)){
			holder.mImage1.setImageResource(R.drawable.item_myloan_in);
			if(data.type.equals("1")){
				holder.mImage1.setVisibility(View.VISIBLE);
			}else{
				holder.mImage1.setVisibility(View.GONE);
			}
		}else{
			holder.mImage1.setImageResource(R.drawable.item_myloan_out);
			if(data.type.equals("1")){
				holder.mImage1.setVisibility(View.VISIBLE);
			}else{
				holder.mImage1.setVisibility(View.GONE);
			}
		}
		if(data.type.equals("1")){
			holder.mImage2.setImageResource(R.drawable.item_myloan_image1);
			holder.mImage2.setVisibility(View.VISIBLE);
		}else if(data.type.equals("2")){
			holder.mImage2.setVisibility(View.VISIBLE);
			holder.mImage2.setImageResource(R.drawable.item_myloan_image2);
		}else if(data.type.equals("3")){
//			holder.mImage2.setVisibility(View.GONE);
			holder.mImage2.setVisibility(View.VISIBLE);
			holder.mImage2.setImageResource(R.drawable.item_myloan_image3);
		}
//		Double money = Double.valueOf(data.quota_money);
//		Double reust = money / 10000;
//		holder.mText_money.setText(reust+"��");
		return convertView;
	}

}
